home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / miscellaneous / science / maths / calc / help / operator < prev    next >
Encoding:
Text File  |  1996-09-07  |  4.1 KB  |  130 lines

  1. Operators
  2.  
  3.     The operators are similar to C, but the precedence of some of
  4.     the operators differs.  In addition, there are several additional
  5.     operators, and some C operators are missing.  The following list
  6.     gives the operators arranged in order of precedence, from the
  7.     least tightly binding to the most tightly binding:
  8.  
  9.     ,    Comma operator.
  10.         For situations in which a comma is used for another purpose
  11.         (function arguments, array indexing, and the print statement),
  12.         parenthesis must be used around the comma operator.
  13.  
  14.     ? :    Conditional value.
  15.         a ? b : c  returns b if a is nonzero, c otherwise.
  16.         Thus it is equivalent to: if (a) return b; else return c;.
  17.         All that is required of the arguments in this function
  18.         is that the is-it-nonzero test is meaningful for a.
  19.  
  20.     =  +=  -=  *=  /=  %=  //=  &=  |=  <<=  >>=  ^=  **=
  21.         Assignments.
  22.  
  23.     ||    Logical OR.
  24.         Unlike C, the result is the first non-zero expression or 0,
  25.         instead of just 0 or 1.  Thus a || b is equivalent to
  26.         a ? a : b.
  27.  
  28.     &&    Logical AND.
  29.         Unlike C, the result is the last expression or 0,
  30.         instead of just 0 or 1.  Thus a && b is equivalent to
  31.         !a ? 0 : (!b ? 0 : b).
  32.  
  33.     ==  !=  <=  >=  <  >
  34.         Relations.
  35.  
  36.     +  -
  37.         Binary plus and minus.
  38.  
  39.     *  /  //  %
  40.         Multiply, divide. and modulo.
  41.         Please Note: The '/' operator is a fractional divide,
  42.         whereas the '//' is an integral divide.  Thus think of '/'
  43.         as division of real numbers, and think of '//' as division
  44.         of integers (e.g., 8 / 3 is 8/3 whereas 8 // 3 is 2).
  45.         The '%' is integral or fractional modulus (e.g., 11%4 is 3,
  46.         and 10%pi() is ~.575222).
  47.  
  48.     |    Bitwise OR.
  49.         In a | b, both a and b are to be real integers;
  50.         the signs of a and b are ignored, i.e.
  51.         a | b = abs(a) | abs(b) and the result will
  52.         be a non-negative integer.
  53.  
  54.     &    Bitwise AND.
  55.         In a & b, both a and b are to be real integers;
  56.         the signs of a and b are ignored as for a | b.
  57.  
  58.     ^  **  <<  >>
  59.         Powers and shifts.
  60.         The '^' and '**' are both exponentiation, e.g. 2^3
  61.         returns 8, 2^-3 returns .125.  In a ^ b, b has to be
  62.         an integer and if a is zero, nonnegative.  0^0 returns
  63.         the value 1.
  64.  
  65.         For the shift operators both arguments are to be
  66.         integers, or if the first is complex, it is to have
  67.         integral real and imaginary parts.  Changing the
  68.         sign of the second argument reverses the shift, e.g.
  69.         a >> -b = a << b.  The result has the same sign as
  70.         the first argument except that a nonzero value is
  71.         reduced to zero by a sufficiently long shift to the
  72.         right.  These operators associate right to left,
  73.         e.g.  a << b ^ c = a << (b ^ c).
  74.  
  75.     +  -  !
  76.         Unary operators.
  77.         The '!' is the logical NOT operator: !a returns 0 if
  78.         a is nonzero, and 1 if a is zero, i.e. it is
  79.         equivalent to a ? 0 : 1.  Be careful about
  80.         using this as the first character of a top level command,
  81.         since it is also used for executing shell commands.
  82.  
  83.     ++  --
  84.         Pre or post incrementing or decrementing.
  85.         These are applicable only to variables.
  86.  
  87.     [ ]  [[ ]]  .  ( )
  88.         Indexing, double-bracket indexing, element references,
  89.         and function calls.  Indexing can only be applied to matrices,
  90.         element references can only be applied to objects, but
  91.         double-bracket indexing can be applied to matrices, objects,
  92.         or lists.
  93.  
  94.     variables  constants  .  ( )
  95.         These are variable names and constants, the special '.' symbol,
  96.         or a parenthesized expression.  Variable names begin with a
  97.         letter, but then can contain letters, digits, or underscores.
  98.         Constants are numbers in various formats, or strings inside
  99.         either single or double quote marks.
  100.  
  101.  
  102.     The most significant difference from the order of precedence in
  103.     C is that | and & have higher precedence than ==, +, -, *, / and %.
  104.     For example, in C a == b | c * d is interpreted as:
  105.  
  106.         (a == b) | (c * d)
  107.  
  108.     and calc it is:
  109.  
  110.         a == ((b | c) * d)
  111.  
  112.  
  113.     Most of the operators will accept any real or complex numbers
  114.     as arguments.  The exceptions are:
  115.  
  116.     /  //  %
  117.         Second argument must be nonzero.
  118.  
  119.     ^
  120.         The exponent must be an integer.  When raising zero
  121.         to a power, the exponent must be non-negative.
  122.  
  123.     |  &
  124.         Both both arguments must be integers.
  125.  
  126.     <<  >>
  127.         The shift amount must be an integer.  The value being
  128.         shifted must be an integer or a complex number with
  129.         integral real and imaginary parts.
  130.